<template>
  <div>
  <div><h1>这个是短信验证码登录页面</h1></div>
  <div class="login">
    <div>
      <el-input placeholder="请输入手机号" v-model="user.phone " clearable class="input-style"></el-input>
      <span v-if="error.name" class="err-msg">{{error.name}}</span>
    </div>

    <div>
      <el-button type="primary" @click="getCodedx" class="login_style">获取验证码</el-button>
    </div>

    <div>
      <el-input placeholder="请输入验证码" v-model="user.code" show-password class="input-style"></el-input>
    </div>


    <div>
      <el-button type="primary" @click="login" class="login_style">登录</el-button>
    </div>

  </div>
  </div>
</template>

<script>
    export default {
      // name: "Login",
      data(){
          return{
            name:'',
            pwd :'',
            error :{
              name: '',
              pwd : ''
            },
            user: {
              userName:'',
              password:'',
              phone:'',
              email:'',
              code:''

            },
            token: ''
          }
      },
      methods:{
        /*          login(){
                            const {name,pwd,$router} = this
                            this.$router.push({
                              name :"Main",
                              params: {
                                username: this.name
                              }
                            });
                          }*/
        login: function () {
          // alert(this.user.password)
          // alert(this.user.userName)
          this.$axios.post("/user/logindx", this.user).then(res => {
            console.log(res.data.code)


            if (res.data.code == 200) {
              alert(res.data.data)


             window.localStorage.setItem("userS",JSON.stringify(res.data.data));

              alert(res.data.message)
              this.$router.push("/")
            } else {
              alert(res.data.message)
              // this.login()
            }
          })


        },
        getCodedx:function () {
          this.$axios.post("/user/getCode",this.user).then(res=>{
            alert(res.data.message);
          })
        }
      }
    }
</script>

<style>

  .login{
    margin-top: 200px;
  }
  .input_style{
    width: 200px;
    margin-bootom:10px;
  }
  .login_style{
    width: 200px;
  }
</style>
